package com.shop.goods.controller;

import com.shop.domain.Spec;
import com.shop.entity.Result;
import com.shop.goods.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品规格
 */
@RestController
@RequestMapping("/Spec")
@CrossOrigin
public class SpecController {
    @Autowired
    private SpecService specService;

    /**
     * 查询全部
     *
     * @return
     */
    @GetMapping("/selectAll")
    public Result<List<Spec>> selectAll() {
        return new Result<>("查询成功", specService.selectAll());
    }

    /**
     * 添加规格
     * @param spec
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody Spec spec) {
        specService.insert(spec);
        return new Result<>("新增成功");

    }
    /**
     * 修改规格
     * @param spec
     * @return
     */
    @PostMapping("/update")
    public Result update(@RequestBody Spec spec){
        specService.update(spec);
        return new Result<>("修改成功");
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @GetMapping("/delete")
    public Result delete(@RequestParam Long id){
        specService.delete(id);
        return new Result<>("删除成功");
    }
    /**
     * 条件查询
     * @param spec
     * @return
     */
    @PostMapping("/selectList")
    public Result< List<Spec> > select(@RequestBody Spec spec){
        return new Result<>("条件查询成功",specService.selectList(spec));
    }


}